package org.vidi.jms.topic;

import org.vidi.jms.common.ConnectionUtils;
import org.vidi.jms.common.Constants;

import javax.jms.*;

/**
 * @author vidi
 */
public class SimpleTopicSender {

    private static final String MESSAGE_1 = "TOPIC-MESSAGE-1";
    private static final String MESSAGE_2 = "TOPIC-MESSAGE-2";

    public static void main(String[] args) throws JMSException {
        TopicConnectionFactory factory = (TopicConnectionFactory) ConnectionUtils.getConnectionFactory();
        TopicConnection connection = factory.createTopicConnection();
        connection.start();
        TopicSession session = connection.createTopicSession(false, TopicSession.DUPS_OK_ACKNOWLEDGE);
        Topic topic1 = session.createTopic(Constants.SIMPLE_TOPIC_NAME_1);
        Topic topic2 = session.createTopic(Constants.SIMPLE_TOPIC_NAME_2);

        TopicPublisher publisher1 = session.createPublisher(topic1);
        TopicPublisher publisher2 = session.createPublisher(topic2);

        publisher1.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
        publisher2.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

        TextMessage message1 = session.createTextMessage(MESSAGE_1);
        publisher1.publish(message1);
        TextMessage message2 = session.createTextMessage(MESSAGE_2);
        publisher2.publish(message2);

        session.close();
        connection.close();
    }
}
